/*
 * ReverseGeocoder.java
 *
 * Created on 19 fevrier 2008, 16:32
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package arcweb;

//import arcweb.address.*;
import java.util.Date;

/**
 *
 * @author defautce
 */
public class ReverseGeocoder {
    private static ReverseGeocoder reverseGeocoder=null;
    private String token;
    private Date tokenExpiration;    
    
    private ReverseGeocoder() throws Exception{ //Singleton implementation
        token=getToken();
    
    }
   public static ReverseGeocoder create() throws Exception { //Singleton implementation
        if(ReverseGeocoder.reverseGeocoder==null){
            return new ReverseGeocoder();   
        }else{
            return ReverseGeocoder.reverseGeocoder;        
        }
        
        
    }
     private String getToken() throws Exception{        
       /* arcweb.authentication.Authentication service = new arcweb.authentication.Authentication();
        arcweb.authentication.IAuthentication port = service.getAuthenticationHttpPort();
        // TODO initialize WS operation arguments here
        java.lang.String username = "windson";
        java.lang.String password = "wind2505";
        // TODO process result here
        tokenExpiration=new Date();
        tokenExpiration.setTime(tokenExpiration.getTime()+300000); //50 minutes is the token expiration time
        token=port.getToken(username, password);     
*/
        return ""; 
    }
     /*
     public Address getAddressByCoordinates(double latitude, double longitude) throws Exception{
         Address address=null;
         Date currentDate=new Date();
         if(!currentDate.before(tokenExpiration)){ //Token is still valid
            token=getToken();         
         }
            AddressManager service = new AddressManager();
            IAddressManager port = service.getAddressManagerHttpPort();
            
            ArrayOfPoint points = new ArrayOfPoint();
            
            //Creating points with coordinates
            Point point= new Point();
            point.setX(longitude);
            point.setY(latitude);     
             
            points.getPoint().add(point);           
            
            //Setting Address Finder Options
            AddressFinderOptions myAddressFinderOptions = new AddressFinderOptions();
            myAddressFinderOptions.setDataSource("auto"); //Searching Automatic DataSources
            myAddressFinderOptions.setExtendedPostalCode(false);
            myAddressFinderOptions.setPartialAddress(false);
            myAddressFinderOptions.setSnapType("house");
            
           arcweb.address.ArrayOfAddressInfo webServicesResult = port.findAddressesByPoint(points, myAddressFinderOptions, token);
            
            if(webServicesResult.getAddressInfo().size()>0){                
                address= webServicesResult.getAddressInfo().get(0).getAddress();
            }         
         return address;
     }
    */
}
